//index.js
//获取应用实例
const app = getApp();

Page({

  /**
   * 页面的初始数据
   */
  data: {
    tab: 0,
    pullfreshview: false,
    dataObj_TW: [],
    dataObj_CY: [], //产品参数数据源
    dataObj_GY: [], //关于数据源
    swiperHeight: 0,
    swiperHeight_CY: 0,
    swiperHeight_GY: 0,
    boxHeight: 0,
    nowCurrent: '0', //当前菜单下标
    tabSlide1: true, //三个菜单，默认没有切换过
    tabSlide2: false,
    tabSlide3: false,
    loadingHint: '',
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    this.setDataFunctionTW();
  },

  /**
   * 设置图文数据
   */
  setDataFunctionTW: function () {
    var that = this;
    for (var i = 0; i < 20; i++) {
      that.data.dataObj_TW.push('图文详情');
      that.setData({
        swiperHeight: that.data.swiperHeight + 40,//每新增体一条数据，增加一行的高度45
      })
    }
    that.setData({
      boxHeight: 0,
      dataObj_TW: that.data.dataObj_TW,
      boxHeight: that.data.swiperHeight,
      swiperHeight: that.data.swiperHeight,
      loadingHint: '上拉加载...',
    })
  },

  /**
  * 设置产品参数数据
  */
  setDataFunctionCP: function () {
    var that = this;
    for (var i = 0; i < 10; i++) {
      that.data.dataObj_CY.push('产品参数');
      that.setData({
        swiperHeight_CY: that.data.swiperHeight_CY + 40,//每新增体一条数据，增加一行的高度45
      })
    }
    console.log(that.data.boxHeight)
    that.setData({
      boxHeight:0,
      dataObj_CY: that.data.dataObj_CY,
      boxHeight: that.data.swiperHeight_CY,
      swiperHeight_CY: that.data.swiperHeight_CY,
    })
    console.log(that.data.boxHeight)
    if (that.data.dataObj_CY.length <= 10){
      that.setData({
        loadingHint: '- 就这么多了 -',
      })
    }
    else{
      that.setData({
        loadingHint: '上拉加载...',
      })
    }
  },

  /**
  * 设置关于数据
  */
  setDataFunctionGY: function () {
    var that = this;
    for (var i = 0; i < 20; i++) {
      that.data.dataObj_GY.push('关于');
      that.setData({
        swiperHeight_GY: that.data.swiperHeight_GY + 40,//每新增体一条数据，增加一行的高度45
      })
    }
    that.setData({
      dataObj_GY: that.data.dataObj_GY,
      boxHeight: that.data.swiperHeight_GY,
      swiperHeight_GY: that.data.swiperHeight_GY,
      loadingHint: '上拉加载...',
    })
  },

  /**
   * 滑动切换tab
   */
  tabbarSlide: function (e) {
    var that = this;
    that.setData({
      tab: e.detail.current,
      nowCurrent: e.detail.current,
    });
    //图文详情
    if (that.data.nowCurrent == 0) {
      //设置当前容器高度为对应内容的高度
      that.setData({
        boxHeight: e.currentTarget.dataset.item_a,
      })
      if (that.data.tabSlide1 == false) {
        this.setDataFunctionTW();
        that.setData({
          tabSlide1: true,
          // tabSlide2: false,
          // tabSlide3: false,
        })
      }
      return;
    }
    //产品参数
    if (that.data.nowCurrent == 1) {
      //设置当前容器高度为对应内容的高度
      that.setData({
        boxHeight: e.currentTarget.dataset.item_b,
      })
      if (that.data.tabSlide2 == false) {
        this.setDataFunctionCP();
        that.setData({
          // tabSlide1: false,
          tabSlide2: true,
          // tabSlide3: false,
        })
      }
      return;
    }
    //关于
    if (that.data.nowCurrent == 2) {
      //设置当前容器高度为对应内容的高度
      that.setData({
        boxHeight: e.currentTarget.dataset.item_c,
      })
      if (that.data.tabSlide3 == false) {
        this.setDataFunctionGY();
        that.setData({
          // tabSlide1: false,
          // tabSlide2: false,
          tabSlide3: true,
        })
      }
      return;
    }
  },

  /**
   * 点击tab切换
   */
  tabbarClick: function (e) {
    var that = this;
    if (that.data.tab === e.target.dataset.current) {
      return false;
    } else {
      that.setData({
        tab: e.target.dataset.current,
        pullfreshview: true,
        nowCurrent: e.target.dataset.current,
      })
      //图文详情
      if (that.data.nowCurrent == 0) {
        //设置当前容器高度为对应内容的高度
        that.setData({
          boxHeight: e.currentTarget.dataset.item_a,
        })
        if (that.data.tabSlide1 == false) {
          this.setDataFunctionTW();
          that.setData({
            tabSlide1: true,
          })
        }
      }
      //产品参数
      if (that.data.nowCurrent == 1) {
        //设置当前容器高度为对应内容的高度
        that.setData({
          boxHeight: e.currentTarget.dataset.item_b,
        })
        if (that.data.tabSlide2 == false) {
          this.setDataFunctionCP();
          that.setData({
            tabSlide2: true,
          })
        }
      }
      //关于
      if (that.data.nowCurrent == 2) {
        //设置当前容器高度为对应内容的高度
        that.setData({
          boxHeight: e.currentTarget.dataset.item_c,
        })
        if (that.data.tabSlide3 == false) {
          this.setDataFunctionGY();
          that.setData({
            tabSlide3: true,
          })
        }
      }
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    var that = this;
    console.log(that.data.nowCurrent)
    //图文详情
    if (that.data.nowCurrent == 0) {
      this.setData({
        pullfreshview: true,
        loadingHint: "加载中..."
      })
      setTimeout(function () {
        that.setDataFunctionTW();
      }, 500)
    }
    //产品参数
    if (that.data.nowCurrent == 1) {
      this.setData({
        pullfreshview: true,
        loadingHint: "加载中..."
      })
      setTimeout(function () {
        that.setDataFunctionCP();
      }, 500)
    }
    //关于
    if (that.data.nowCurrent == 2) {
      this.setData({
        pullfreshview: true,
        loadingHint: "加载中..."
      })
      setTimeout(function () {
        that.setDataFunctionGY();
      }, 500)
    }
  },

  pageScrollTo: function () {
    wx.pageScrollTo({
      scrollTop: 0,
    })
  },

})